const db = require('../db/index');
const DataType = require('sequelize');
const User = require('./User');
/**es6继承 订单表*/
class Order extends DataType.Model {}
Order.init(
    {
        id: {
            type: DataType.INTEGER,
            allowNull: false,
            autoIncrement: true,
            primaryKey: true
        },
        orderId: {
            type: DataType.STRING,
            comment: '订单号',
            defaultValue: 0,
            allowNull: false
        },
        userId: {
            type: DataType.INTEGER,
            comment: '用户ID',
            allowNull: false
        },
        group: {
            type: DataType.INTEGER,
            comment: '类型 1 会员 2次卡',
            defaultValue: 1,
            allowNull: false
        },
        goodId: {
            type: DataType.INTEGER,
            comment: '商品ID',
            defaultValue: 1,
            allowNull: false
        },
        desc: {
            type: DataType.STRING,
            comment: '订单信息描述',
            defaultValue: 0,
            allowNull: false
        },
        amount: {
            type: DataType.DECIMAL(10, 2),
            comment: '实际金额',
            defaultValue: 0,
            allowNull: false
        },
        status: {
            type: DataType.BOOLEAN,
            comment: '0未付款 1已付款',
            defaultValue: 1,
            allowNull: false
        }
    },
    {
        tableName: 'order',
        modelName: 'order',
        sequelize: db
    }
);
// Order.sync({ force: true });
Order.belongsTo(User['default'], { as: 'userData', foreignKey: 'userId' });
exports['default'] = Order;
